﻿using BPMN.appilcation.IService;
using BPMN.Domid.Dto.UserDtos;
using BPMN.Domid.Model.Users;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Text;

namespace BPMNWebAPI.Controllers
{
    /// <summary>
    /// 用户接口
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly IUserService user;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="user"></param>
        public UserController(IUserService user)
        {
            this.user = user;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add(User entity)
        {
            return Ok(await user.Add(entity));
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> Delete(int id)
        {
            return Ok(await user.Delete(id));
        }
        /// <summary>
        /// 条件查询
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get(int id)
        {
            return Ok(await user.Get(id));
        }
        /// <summary>
        /// 查询全部数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetAll()
        {
            return Ok(await user.GetAll());
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> Update(User entity)
        {
            return Ok(await user.Update(entity));
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AddUser(UsersDto dto)
        {
            try
            {
                return Ok(await user.AddUser(dto));
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        
        public async Task<IActionResult> GetLong(UsersDto dto)
        {
            try
            {
               
                return Ok(await user.GetLong(dto));
            }
            catch (Exception)
            {

                throw;
            }
        }
       
    }
}
